import { encryptAES, decryptAES } from '@/utils/encryption'

// 设置sessionStorage
export const setSessionInfo = (key, value) => {
  const storage = window.sessionStorage
  const svalue = {
    data: value
  }
  storage.setItem(key, JSON.stringify(svalue))
}

// 获取sessionStorage
export const getSessionInfo = function (key) {
  const storage = window.sessionStorage
  const svalue = storage.getItem(key)
  let value = ''
  if (svalue !== undefined && svalue !== null && svalue !== '') {
    const tmp = JSON.parse(svalue)
    value = tmp.data
  }
  return value
}

// 移除sessionStorage
export const removeSessionInfo = function (key) {
  const storage = window.sessionStorage
  storage.removeItem(key)
}

// 设置localStorage
export const setLocalInfo = function (key, value) {
  const storage = window.localStorage
  const svalue = {
    data: value
  }
  storage.setItem(key, encryptAES(JSON.stringify(svalue)))
}

// 获取localStorage
export const getLocalInfo = function (key) {
  const storage = window.localStorage
  const svalue = storage.getItem(key)
  let value = ''
  if (svalue !== undefined && svalue !== null && svalue !== '') {
    const tmp = JSON.parse(decryptAES(svalue))
    value = tmp.data
  }
  return value
}
// 移除localStorage
export const removeLocalInfo = function (key) {
  const storage = window.localStorage
  storage.removeItem(key)
}
